DB_HOST = 
DB_NAME = ${DB_UNAME}
DB_UNAME = 
DB_UPASS = 

.PHONY : config php_config db_config doc \
	config_clean doc_clean clean
PHP_INC = ../config.inc
PHP_DOC = ../_doc

config : db_config php_config
doc : ${PHP_DOC}
${PHP_DOC} : ../auth.php ../app/*
	for fn in $? ; do phpdoc -f $$fn -t $@ ; done

php_config : ${PHP_INC}
${PHP_INC} : php_config.inc
	printf "<?php\
	\ndefine('DB_HOST', "${DB_HOST}");\
	\ndefine('DB_NAME', "${DB_NAME}");\
	\ndefine('DB_UNAME', "${DB_UNAME}");\
	\ndefine('DB_UPASS', "${DB_UPASS}");\
	\n" > $@
	cat php_config.inc >> $@
	echo "?>" >> $@

db_config : tb.creating.sql
	mysql ${DB_NAME} -h ${DB_HOST} -u ${DB_UNAME} -p${DB_UPASS} < tb.creating.sql

clean : doc_clean config_clean
doc_clean :
	rm -fr ${PHP_DOC}/*

config_clean : tb.deleting.sql
	rm -f ${PHP_INC}
	-mysql ${DB_NAME} -h ${DB_HOST} -u ${DB_UNAME} -p < tb.deleting.sql
